package com.vone.until.db;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;

public class FileUtil {
	/**
	 * 复制配置文件到本地
	 * 
	 * @param fileName
	 */
	public static void copyConfigFile(String fileName) {
		try {
			int byteread = 0;
			InputStream inStream = FileUtil.class.getResourceAsStream("/" + fileName); // 读入原文件

			FileOutputStream fs = new FileOutputStream("./" + fileName);
			byte[] buffer = new byte[1444];
			while ((byteread = inStream.read(buffer)) != -1) {
				fs.write(buffer, 0, byteread);
			}
			inStream.close();
			fs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 保存配置文件
	 * 
	 * @param prop
	 * @param fileName
	 * @param remark
	 * @throws Exception
	 */
	public static boolean saveSystemConfig(Properties prop, String fileName, String remark) {
		String fileStr;
		try {
			fileStr = new File(("./" + fileName)).getAbsolutePath();
			FileOutputStream fos;
			fos = new FileOutputStream(fileStr);
			prop.store(fos, remark);
			fos.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}
